<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>紫色鹭</title>
    <link rel="stylesheet" href="../css/common.css">
    <link rel="stylesheet" href="../css/style.css">
    <link rel="stylesheet" href="../layui/css/layui.css">
</head>
<body>
<iframe id="header_01" src="head_01.html" frameborder="0"></iframe>
<div id="head_search_html">
    <iframe id="head_search" src="head_search.html" frameborder="0"></iframe>
</div>
<div class="container store_banner clearfix">
    <div class="store_tab">
        <a href="store_info.html">基本信息</a>
        <a class="active">轮播管理</a>
        <a href="store_product.html">商品管理</a>
        <a href="store_manage.html">订单管理</a>
        <!--<a href="store_evaluate.html">评价管理</a>-->
    </div>
    <div class="right">
        <div class="add_banner">
            <div class="title">
                新增轮播图
                <div class="button button-styblack" onclick="history.go(-1)">返回</div>
            </div>
            <div class="mt30">
                <span class="p-a">图片：</span>
                <div class="layui-upload lay-input-sty">
                    <button type="button" class="layui-btn button-sty" id="test1">+</button>
                    <div class="layui-upload-list">
                        <img class="layui-upload-img" id="demo1">
                        <p id="demoText"></p>
                    </div>
                </div>
            </div>
            <div class="mt-20">
                <span>跳转链接：</span>
                <input type="text" id="link" class="link-input-sty">
            </div>
            <div class="mt-20">
                <div class="mb15">详情内容：</div>
                <textarea id="demo" style="display: none;"></textarea>
            </div>
            <div class="submit mt10">提交</div>
        </div>

    </div>
</div>
<div class="tabRight">
    <div class="first">
        <ul>
            <li><a target="_blank" class="icon_admin_white" title=""></a></li>
            <li>
                <a target="_blank" class="go-shopcard c-fff">
                    <i class="icon_shopcar_white"></i>
                    <p class="mt10">购<br>物<br>车</p>
                    <span class="car-num pos-Sty1">0</span>
                </a>
            </li>
            <li>
                <a target="_blank" class="icon_list_white mt10 go-myorder" title="订单"></a>
                <a target="_blank" class="icon_collect_white mt10 go-myhas" title="收藏"></a>
                <a target="_blank" class="icon_history_white mt10 go-record" title="记录"></a>
            </li>
        </ul>
    </div>
    <div class="second">
        <a target="_blank" class="icon_edit_white"></a>
        <a target="_blank" class="icon_top_white mt10"></a>
    </div>
</div>
<script src="../js/config.js"></script>

<script>
    var layedit;
    var edit;
    var layer;
    var pngUrl = '';
    layui.use('layedit', function() {
        layedit = layui.layedit;
        layedit.set({
            uploadImage: {
                url: baseUrl+'/file/layeditUplode?token='+Token,
                type:"post"
            }
        });
        edit = layedit.build('demo');
    })

    //编辑回显？
    get_ajax("/sys/banner/info",{id:getUrlParam('id')},function (data) {
        if(data){
            $('#link').val(data.link);
            $('#demo1').attr('src',imgBaseUrl+data.picUrl);
            layedit.setContent(edit,data.content);
            pngUrl = data.picUrl;
        }
    })

    //图片上传
    layui.use(['upload'], function() {
        var $ = layui.jquery, upload = layui.upload;
        //普通图片上传
        var uploadInst = upload.render({
            elem: '#test1'
            , url: baseUrl+'/file/upload?token='+Token
            , before: function (obj) {
                //预读本地文件示例，不支持ie8
                obj.preview(function (index, file, result) {
                    $('#demo1').attr('src', result); //图片链接（base64）
                });
            }
            , done: function (res,index) {
                //如果上传失败
                if (res.code > 0) {
                    return layer.msg('上传失败');
                }else{
                    var item = this.item;
                    var data = res.data;
                    this.item.attr("picUrl",data.address);
                    this.item.attr("picId",data.id);
                }

            }
            , error: function () {

            }
        });
    })

    //提交轮播
    $(document).on('click','.submit',function(){
        var picUrl = $("#test1").attr("picUrl") || pngUrl;
        var link = $("#link").val();
        var content = layedit.getContent(edit);
        if(!picUrl){
            layer.msg("请上传图片！")
            return;
        }
        get_ajax("/sys/banner/add",{picUrl:picUrl,link:link,content:content,type:2},function (data) {
            layer.msg('保存成功！');
            $('#link').val('');
            $('#demo1').attr('src','');
            layedit.setContent(edit,'');
            setTimeout(function(){
                history.go(-1);
            },1000)

        })

    })




</script>
</body>
</html>